//
//  WDScanCodeViewModel.h
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/7.
//

#import "TYZBaseViewModel.h"
#import <AVFoundation/AVFoundation.h>
#import "WDArrivalScanCarRequest.h" // 到站服务-车辆扫码
#import "WDRescueScanCarRequest.h" // 外出救援 - 车辆扫码

NS_ASSUME_NONNULL_BEGIN


#define BootomViewHeight 140 //条形码底部的控件部分高度(包括扫描说明,按钮)
#define InPutAndLightBtnWidth 120  //手动输入按钮和开关灯按钮的宽度
#define InPutAndLightBtnHeight 60  //手动输入按钮和开关灯按钮的高度
#define LightBtnMarginInputBtn 20  //手动输入按钮和开关灯按钮之间的距离

/// 扫码
@interface WDScanCodeViewModel : TYZBaseViewModel

/// 1 表示来自到站服务；2 表示来自外出救援
@property (nonatomic, assign) NSInteger fromWhere;

@property (nonatomic, assign) CGRect scanRect;//扫描区域的frame

@property (nonatomic, assign) BOOL isShowLightBtn;
@property (nonatomic, assign) BOOL isShowInputBtn;
@property (nonatomic, copy) NSString *inputBtnTitle;
@property (nonatomic, copy) NSString *tipMsg;

/// 下方描述
@property (nonatomic, copy) NSString *tipInfo;

@property (nonatomic, strong) AVCaptureDevice *device;
@property (nonatomic, strong) AVCaptureDeviceInput *deviceInput;
@property (nonatomic, strong) AVCaptureMetadataOutput *dataOutput;
@property (nonatomic, strong, nullable) AVCaptureSession *session;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;

@property (nonatomic, copy) void(^touchScanCodeResultBlock)(NSString *scanCode, NSString *scanType);


/// 到站服务-车辆扫码 -- 请求参数
@property (nonatomic, strong) WDArrivalScanCarReqModel *arrivalReqModel;

/// 外出救援-车辆扫码 -- 请求参数
@property (nonatomic, strong) WDRescueScanCarReqModel *rescueReqModel;

/// 服务工单
@property (nonatomic, strong, nullable) WDArrivalServiceItemModel *serviceItemModell;


- (UIImage *)imageWithName:(NSString *)imageName;

- (void)setupSession:(UIViewController *)vc;

/// 开始扫描
- (void)startScan:(void(^)(void))completion;

/// 停止扫描
- (void)stopScan:(void(^)(void))completion;

- (void)turnTorch:(BOOL)on;


/// 判断相机是否可用
- (BOOL)isCameraAvailable;

/// 判断前置相机是否可用
- (BOOL)isFrontCameraAvailable;

/// 是否有后置摄像头
- (BOOL)isRearCameraAvailable;

/// 摄像头验证状态是否正确
- (BOOL)isCameraAuthStatusCorrect;




/// 到站服务-扫码车辆
/// - Parameter completion: completion description
- (void)requestWithArrivalScanCar:(RequestCompletionBlock)completion;

/// 外出救援-扫码车辆
/// - Parameter completion: completion description
- (void)requestWithRescueScanCar:(RequestCompletionBlock)completion;


@end

NS_ASSUME_NONNULL_END
